// Copyright (c) 2017-2023 Cloudflare, Inc.
// Licensed under the Apache 2.0 license found in the LICENSE file or at:
//     https://opensource.org/licenses/Apache-2.0
import * as assert from 'node:assert';
import {
  createInstrumentationState,
  createTailStreamHandler,
  runInstrumentationTest,
} from 'instrumentation-test-helper';

// Create module-level state using the helper
const state = createInstrumentationState();

export default {
  tailStream: createTailStreamHandler(state),
};

export const test = {
  async test() {
    await runInstrumentationTest(state, expectedSpans, {
      testName: 'D1 instrumentation',
      mapFn: (span) => {
        // varies test-by-test because random duration in d1-mock.js
        if (span['http.response.body.size']) {
          span['http.response.body.size'] = 0n;
        }
        return span;
      },
    });
  },
};

const expectedSpans = [
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/execute?resultsFormat=NONE',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 231n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_run',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'run',
    'db.query.text':
      ' CREATE TABLE users\n' +
      '        (\n' +
      '            user_id    INTEGER PRIMARY KEY,\n' +
      '            name       TEXT,\n' +
      '            home       TEXT,\n' +
      '            features   TEXT,\n' +
      '            land_based BOOLEAN\n' +
      '        );',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 1,
    'cloudflare.d1.response.rows_written': 2,
    'cloudflare.d1.response.last_row_id': 0,
    'cloudflare.d1.response.changed_db': true,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 42n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_all',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'all',
    'db.query.text': 'SELECT * FROM users;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 1,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 0,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/execute?resultsFormat=NONE',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 42n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_run',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'run',
    'db.query.text': 'SELECT * FROM users;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 1,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 0,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/execute?resultsFormat=NONE',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 40n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_run',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'run',
    'db.query.text': 'DELETE FROM users;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 0,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 0,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 223n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_all',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'all',
    'db.query.text':
      '\n' +
      '        INSERT INTO users (name, home, features, land_based) VALUES\n' +
      "          ('Albert Ross', 'sky', 'wingspan', false),\n" +
      "          ('Al Dente', 'bowl', 'mouthfeel', true)\n" +
      '        RETURNING *\n' +
      '    ',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 4,
    'cloudflare.d1.response.rows_written': 2,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': true,
    'cloudflare.d1.response.changes': 2,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/execute?resultsFormat=NONE',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 40n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_run',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'run',
    'db.query.text': 'DELETE FROM users;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 0,
    'cloudflare.d1.response.rows_written': 2,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': true,
    'cloudflare.d1.response.changes': 2,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/execute?resultsFormat=NONE',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 223n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_run',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'run',
    'db.query.text':
      '\n' +
      '        INSERT INTO users (name, home, features, land_based) VALUES\n' +
      "          ('Albert Ross', 'sky', 'wingspan', false),\n" +
      "          ('Al Dente', 'bowl', 'mouthfeel', true)\n" +
      '        RETURNING *\n' +
      '    ',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 4,
    'cloudflare.d1.response.rows_written': 2,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': true,
    'cloudflare.d1.response.changes': 2,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 31n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_all',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'all',
    'db.query.text': 'select 1;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 0,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 31n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_all',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'raw',
    'db.query.text': 'select 1;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 0,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 31n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_first',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'first',
    'db.query.text': 'select 1;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 0,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 31n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_first',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'first',
    'db.query.text': 'select 1;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 0,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 42n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_all',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'all',
    'db.query.text': 'SELECT * FROM users;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 2,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 42n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_all',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'raw',
    'db.query.text': 'SELECT * FROM users;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 2,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 42n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_first',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'first',
    'db.query.text': 'SELECT * FROM users;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 2,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 42n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_first',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'first',
    'db.query.text': 'SELECT * FROM users;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 2,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 61n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_all',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'all',
    'db.query.text': 'SELECT * FROM users WHERE user_id = ?;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 1,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 61n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_all',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'raw',
    'db.query.text': 'SELECT * FROM users WHERE user_id = ?;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 1,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 61n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_first',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'first',
    'db.query.text': 'SELECT * FROM users WHERE user_id = ?;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 1,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 61n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_first',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'first',
    'db.query.text': 'SELECT * FROM users WHERE user_id = ?;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 1,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 61n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_all',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'all',
    'db.query.text': 'SELECT * FROM users WHERE user_id = ?;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 1,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 61n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_all',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'raw',
    'db.query.text': 'SELECT * FROM users WHERE user_id = ?;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 1,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 61n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_first',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'first',
    'db.query.text': 'SELECT * FROM users WHERE user_id = ?;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 1,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 61n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_first',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'first',
    'db.query.text': 'SELECT * FROM users WHERE user_id = ?;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 1,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 125n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_batch',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'batch',
    'db.query.text':
      'SELECT * FROM users WHERE user_id = ?;\n' +
      'SELECT * FROM users WHERE user_id = ?;',
    'db.operation.batch.size': 2,
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 2,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 79n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_first',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'first',
    'db.query.text': 'SELECT count(1) as count FROM users WHERE land_based = ?',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 2,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 79n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_first',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'first',
    'db.query.text': 'SELECT count(1) as count FROM users WHERE land_based = ?',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 2,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 79n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_first',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'first',
    'db.query.text': 'SELECT count(1) as count FROM users WHERE land_based = ?',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 2,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 79n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_first',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'first',
    'db.query.text': 'SELECT count(1) as count FROM users WHERE land_based = ?',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 2,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 79n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_first',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'first',
    'db.query.text': 'SELECT count(1) as count FROM users WHERE land_based = ?',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 8192,
    'cloudflare.d1.response.rows_read': 2,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 2,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 298n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_batch',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'batch',
    'db.query.text':
      'CREATE TABLE abc (a INT, b INT, c INT);\n' +
      'CREATE TABLE cde (c TEXT, d TEXT, e TEXT);\n' +
      'INSERT INTO abc VALUES (1,2,3),(4,5,6);\n' +
      'INSERT INTO cde VALUES ("A", "B", "C"),("D","E","F"),("G","H","I");',
    'db.operation.batch.size': 4,
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 16384,
    'cloudflare.d1.response.rows_read': 2,
    'cloudflare.d1.response.rows_written': 9,
    'cloudflare.d1.response.last_row_id': 3,
    'cloudflare.d1.response.changed_db': true,
    'cloudflare.d1.response.changes': 5,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 45n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_all',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'all',
    'db.query.text': 'SELECT * FROM abc, cde;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 16384,
    'cloudflare.d1.response.rows_read': 8,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 3,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 45n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_all',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'raw',
    'db.query.text': 'SELECT * FROM abc, cde;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 16384,
    'cloudflare.d1.response.rows_read': 8,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 3,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 45n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_all',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'raw',
    'db.query.text': 'SELECT * FROM abc, cde;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 16384,
    'cloudflare.d1.response.rows_read': 8,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 3,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 45n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_all',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'raw',
    'db.query.text': 'SELECT * FROM abc, cde;',
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 16384,
    'cloudflare.d1.response.rows_read': 8,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 3,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 76n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_all',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'all',
    'db.query.text': "SELECT * from cde WHERE c IN ('A','B','C','X','Y','Z')",
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 16384,
    'cloudflare.d1.response.rows_read': 3,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 3,
    'cloudflare.d1.response.changed_db': false,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
  {
    name: 'fetch',
    'network.protocol.name': 'http',
    'network.protocol.version': 'HTTP/1.1',
    'http.request.method': 'POST',
    'url.full': 'http://d1/query?resultsFormat=ROWS_AND_COLUMNS',
    'http.request.header.content-type': 'application/json',
    'http.request.body.size': 117n,
    'http.response.status_code': 200n,
    'http.response.body.size': 0n,
    closed: true,
  },
  {
    name: 'd1_batch',
    'db.system.name': 'cloudflare-d1',
    'db.operation.name': 'batch',
    'db.query.text': 'DROP TABLE users;\nDROP TABLE abc;\nDROP TABLE cde;',
    'db.operation.batch.size': 3,
    'cloudflare.binding.type': 'D1',
    'cloudflare.d1.response.size_after': 4096,
    'cloudflare.d1.response.rows_read': 9,
    'cloudflare.d1.response.rows_written': 0,
    'cloudflare.d1.response.last_row_id': 3,
    'cloudflare.d1.response.changed_db': true,
    'cloudflare.d1.response.changes': 0,
    closed: true,
  },
];
